package com.hqyj.tmall.service.serviceImpl;

import com.hqyj.mapper.OrderItemMapper;
import com.hqyj.pojo.OrderItem;
import com.hqyj.tmall.service.OrderItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderItemServiceImpl implements OrderItemService {
    @Resource
    private OrderItemMapper orderItemMapper;
    @Override
    public String addByOrderItem(OrderItem orderItem) {
        //先查看数据库中的订单项有没有同类产品，有就只修改数量，没有就添加

        OrderItem orderItem1=orderItemMapper.selectByProductId(orderItem.getProductId());//根据产品ID查找订单项
        if(orderItem1==null){
            int a=orderItemMapper.addByOrderItem(orderItem);
            if(a>0){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            int b=orderItemMapper.UpdateByOrderItem(orderItem);//根据产品Id修改订单项
            if(b>0){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }

    }

    @Override
    public int addsOrderItem(List<OrderItem> list) {
        int a=orderItemMapper.addsOrderItem(list);
        return a;
    }


}
